package hanjia;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/17-下午3:47
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode860 {


    public boolean lemonadeChange(int[] bills) {
        if (bills.length == 1) {
            return bills[0] == 5;
        }
        int five = 0;
        int ten = 0;
        int twenty = 0;

        for (int i : bills) {


            if (i == 5) {
                five++;

            } else if (i == 10) {
                ten++;
                if (five<=0) {
                    return false;
                }
                five--;

            } else {
                if (ten>0){
                    if (five<=0){
                        return false;
                    }
                    ten--;
                    five--;
                }else {
                    if (five<3){
                        return false;
                    }
                    five-=3;


                }

            }


        }
        return true;


    }
}
